package com.baor.security;

import com.baor.config.JwtConfig;
import com.baor.domain.UserVo;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Component
public class TokenService {

    @Autowired
    private JwtConfig jwtConfig;

    //生成token
    public String createToken(UserVo vo) {
        return jwtConfig.createToken(vo);
    }

    //获取主体信息
    public Claims getBody(String token) {
        Claims claims = null;
        if (!isTokenExpire(token)) {
            claims = jwtConfig.getClaims(token);
        }
        return claims;
    }
    //判断token是否过期
    public boolean isTokenExpire(String token) {
        return jwtConfig.isTokenExpired(token);
    }

}
